<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form action="" method="post" onsubmit="return false" lay-filter="deliver_edit_form" class="layui-form">
    <div class="layui-form layuimini-form" id="addSale">
        <div class="layui-form-item">
            <label class="layui-form-label required">编号</label>
            <div class="layui-input-block">
                <input type="text" name="id" v-model="sales.chc_id" autocomplete="off" placeholder="请输入编号id" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">客户名称</label>
            <div class="layui-input-block">
                <input type="text" name="cust_name" autocomplete="off" lay-verify="required" lay-reqtext="客户名称不能为空" disabled readonly placeholder="请输入客户名称" value="" class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">机会来源</label>
            <div class="layui-input-block">
                <input type="text" name="source" lay-verify="required" lay-reqtext="机会来源不能为空" placeholder="请输入机会来源" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">成功机率</label>
            <div class="layui-input-block">
                <input type="text" name="rate" lay-verify="required" lay-reqtext="成功机率不能为空" placeholder="请输入成功机率" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">概要</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="概要不能为空" placeholder="请输入概要" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">联系人</label>
            <div class="layui-input-block">
                <input type="text" name="linkman" lay-verify="required" lay-reqtext="联系人名称不能为空" placeholder="请输入联系人名称" disabled readonly value="" class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">联系人电话</label>
            <div class="layui-input-block">
                <input type="number" name="tel" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机号码" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">机会描述</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入机会描述" disabled readonly class="layui-textarea layui-disabled"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">创建人id</label>
            <div class="layui-input-block">
                <input type="text" name="create_id" lay-verify="required"  lay-reqtext="创建人id不能为空" placeholder="请输入创建人id" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">创建人</label>
            <div class="layui-input-block">
                <input type="text" name="create_by" lay-verify="required" lay-reqtext="创建人不能为空" placeholder="请输入创建人名称" value="" disabled readonly class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-inline" style="width: 200px;">
                <input type="text" name="create_date" id="beginDate" placeholder="请输入创建时间" lay-verify="datetime" class="layui-input layui-disabled" disabled readonly lay-key="1">
            </div>
        </div>

        <!--        <div class="layui-form-item">-->
        <!--            <label class="layui-form-label">指派给</label>-->
        <!--            <div class="layui-input-block">-->
        <!--                <select name="type" v-model="sales.chc_due_to" lay-verify="required">-->
        <!--                    <option value="">请选择</option>-->
        <!--                    <option v-for="d in dueName" :value="d.usr_id" >{{d.usr_name}}</option>-->
        <!--                </select>-->
        <!--            </div>-->
        <!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label required">指派给</label>
            <div class="layui-input-block">
                <input type="text" name="due_to" v-model="sales.chc_due_to" lay-verify="required" lay-reqtext="指派人不能为空" placeholder="请输入指派人名称" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">指派时间</label>
            <div class="layui-input-inline" style="width: 200px;">
                <input type="text" name="due_date" id="endDate" placeholder="请输入指派时间" lay-verify="datetime" disabled readonly class="layui-input layui-disabled" lay-key="2">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="saveBtn" lay-filter="saveBtn" class="layui-btn layui-btn-normal" @click="addSales()">确认保存</button>
            </div>
        </div>
    </div>
</form>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/vue.js"></script>
<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script>
    const addSales = new Vue({
        el:"#addSale",
        data:{
            dueName:[],
            rows:'',
            sales:{
                chc_id:'',
                chc_source:'',
                chc_cust_name:'',
                chc_title:'',
                chc_rate:'',
                chc_linkman:'',
                chc_tel:'',
                chc_desc:'',
                chc_create_id:'',
                chc_create_by:'',
                chc_create_date:'',
                chc_due_to:'',
                chc_due_date:'',
                chc_status:''
            }
        },methods:{
            addSales(){
                $.post("http://127.0.0.1:2004/SalChance/update",this.sales,json=>{
                    this.rows = json.data;
                    if (this.rows > 0){
                        var index = layer.alert("指派成功", {
                            icon:1,
                        },function () {

                            // 关闭弹出层
                            layer.close(index);

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.parent.location.reload();

                        });
                    }else{
                        layer.alert("指派失败！",{
                            icon:2,
                        });
                    }
                })
            },
            assignName(){
                $.get("http://127.0.0.1:2004/SysUser/query",json=>{
                    this.dueName = json.data;
                });
            }
        },mounted(){
            this.assignName();
            // layui.element.render();
        }
    })

    // 向子页面的表格赋值，也可向父页面传值
    function child(dataFromFather) {
        layui.use(['form', 'layer'],function (){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer;

            // 表格赋值
            form.val('deliver_edit_form', {
                "id": dataFromFather.chc_id,
                "cust_name": dataFromFather.chc_cust_name,
                "source": dataFromFather.chc_source,
                "rate": dataFromFather.chc_rate,
                "title": dataFromFather.chc_title,
                "linkman": dataFromFather.chc_linkman,
                "tel": dataFromFather.chc_tel,
                "desc": dataFromFather.chc_desc,
                "create_id": dataFromFather.chc_create_id,
                "create_by": dataFromFather.chc_create_by,
                "create_date": dataFromFather.chc_create_date,
                "due_to": dataFromFather.chc_due_to,
                "due_date": dataFromFather.chc_due_date,
                "status": dataFromFather.chc_status,
            });
        });
    }

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            // $.ajax({
            //     type:"post",
            //     url:"http://127.0.0.1:2004/SalChance/update",
            //     data:data.field,
            //     cache:false,
            //     async:true,
            //     success:function (){
            //         layer.alert("指派成功！",{
            //             icon:1,
            //         })
            //     },
            //     error:function (){
            //         layer.alert("指派失败！",{
            //             icon:2,
            //         })
            //     }
            // })

            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
                window.parent.location.reload();

            });

            return false;
        });

    });

    //动态时间控件
    // window.onload = function(){
    //     function getDate(){
    //         debugger;
    //         var today = new Date();
    //         var date;
    //         date = (today.getFullYear()) +"-" + (today.getMonth() + 1 ) + "-" + today.getDate() + "-" + today.getHours() +":"+today.getMinutes()+":"+today.getSeconds();
    //         return date;
    //     }
    //     window.setInterval(function(){
    //         document.getElementById("beginDate").value=getDate();
    //     }, 1000);
    // }

    //时间选择框
    layui.use(['layer', 'form', 'table', 'laydate'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form,
            laydate = layui.laydate,
            table = layui.table;
        var beginDate = laydate.render({//渲染开始时间选择
            elem: '#beginDate', //通过id绑定html中插入的start
            type: 'datetime',
            max: "2099-12-31 23:59:59",//设置一个默认最大值
            done: function (value, dates) {
                endDate.config.min = {
                    year: dates.year,
                    month: dates.month - 1, //关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                };
            }
        });

        var endDate = laydate.render({//渲染结束时间选择
            elem: '#endDate',//通过id绑定html中插入的end
            type: 'datetime',
            min: "1970-1-1 00:00:00",//设置min默认最小值
            done: function (value, dates) {
                beginDate.config.max = {
                    year: dates.year,
                    month: dates.month - 1,//关键
                    date: dates.date,
                    hours: dates.hours,
                    minutes: dates.minutes,
                    seconds: dates.seconds
                }
            }
        });
    });
</script>
</body>
</html>